﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Specification_Pattern
{
    /// <summary>
    ///  最终的工厂类
    /// </summary>
    public class ExpressionBuilder<T> : CompositeSpecification<T>
    {
        /// <summary>
        /// 符合要求的匹配规则
        /// </summary>
        private Func<T, bool> expression;
        /// <summary>
        /// 将创建规则定义传入
        /// </summary>
        /// <param name="expression"></param>
        public ExpressionBuilder(Func<T, bool> expression)
        {
            this.expression = expression;
        }
        /// <summary>
        /// 判断是否满足条件
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool IsSatisfiedBy(T obj)
        {
           return this.expression(obj);
        }
    }
}
